package com.msb;

import com.msb.bean.Book;
import com.msb.bean.Person;
import com.msb.bean.User;
import com.msb.config.ApplicationConfig;
import com.msb.config.MyConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @author sunpeng
 * @Date 2021-07-13 15:18
 */

public class Test1 {

    @Test
    public void testConfig(){
        ApplicationContext context=new AnnotationConfigApplicationContext(MyConfig.class);
        Person person = context.getBean("getPerson", Person.class);
        System.out.println(person);
        Book goodBook = context.getBean("goodBook", Book.class);
        System.out.println(goodBook);
    }

    @Test
    public void testGetBean2(){
        //通过注解的形式获取spring
        ApplicationContext context=new AnnotationConfigApplicationContext(ApplicationConfig.class);
        User user = context.getBean("user", User.class);
        System.out.println(user);
    }

}
